package noobteam.deartrainer.service;

import noobteam.deartrainer.mapper.CourseSelectionsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class CourseSelectionsService {

    @Resource
    private CourseSelectionsMapper courseSelectionsMapper;
    @Resource
    private UserInfoService userInfoService;

    public boolean selectCourse(Map<String, String> map) {
        boolean isSucceed = false;
        try {
            isSucceed = courseSelectionsMapper.selectCourse(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    public boolean dropCourse(Map<String, String> map) {
        boolean isSucceed = false;
        try {
            isSucceed = courseSelectionsMapper.dropCourse(map);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    public boolean deleteSelectionOfStudent(Integer userId) {
        boolean isSucceed = false;
        try {
            isSucceed = courseSelectionsMapper.deleteStudent(userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    public boolean deleteSelectionOfCourse(Integer courseId) {
        boolean isSucceed = false;
        try {
            isSucceed = courseSelectionsMapper.deleteCourse(courseId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return isSucceed;
    }

    public int getCourseSelectionNum(Integer courseId) {
        int num = 0;
        try {
            num = courseSelectionsMapper.getCourseSelectedNumber(courseId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return num;
    }

    public int getStudentSelectionNum(Integer userId) {
        int num = 0;
        try {
            num = courseSelectionsMapper.getStudentSelectionsNumber(userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return num;
    }

    public List<Map<String, Object>> getStudentListByCourseId(int courseId) {
        List<Map<String, Object>> list = null;
        try {
            list = courseSelectionsMapper.getStudentListByCourseId(courseId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String, Object>> getCourseSelectedList(int userId) {
        List<Map<String, Object>> list = null;
        try {
            list = courseSelectionsMapper.getCourseList(userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public List<Map<String, Object>> getStudentListByCourseTypeId(int courseTypeId){
        List<Map<String, Object>> list = null;
        try {
            list = courseSelectionsMapper.getStudentListByCourseTypeId(courseTypeId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

//    public boolean courseRefund(Map<String, String> map) {
//        boolean isSucceed = false;
//        try {
////            int price = courseSelectionsMapper.getCoursePrice(map.get("courseId"));
////            System.out.println("price:=============");
////            userInfoService.addBalance(map.get("userId"),price);
////            courseSelectionsMapper.dropCourse(map);
////            isSucceed = !isSucceed;
//        } catch (Exception e) {
//            e.printStackTrace();
//            return isSucceed;
//        }
//        return isSucceed;
//    }
}
